const koa = require('koa');
const Route = require('koa-router');
const koaBody = require('koa-body');

const app = new koa()
const router = new Route()


router.post('/user', ctx=>{
  let { body,header } = ctx.request;
  let { name, email } = ctx.request.body;
  if(header.role!=="admin" || header.role==undefined) {
    ctx.body = {
      "code": 401,
      "msg": "unauthorized post"
    }
    return false
  }
  if(name=='' || name==undefined || email=='' || email==undefined) {
    ctx.body = {
      "code": 404,
      "msg": "name与email不能为空"
    }
  }else {
    ctx.body = {
      "code": 200,
      "data": { ...body },
      "msg": "上传成功"
    }
  }
})


app.use(koaBody())
app.use(router.routes())
    .use(router.allowedMethods())
app.listen(3000)






